<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script>

        function getResult(num1, num2, operator) {
            switch (operator) {
                case '+':
                    re = parseFloat(num1) + parseFloat(num2);
                    break;
                case '-':
                    re = parseFloat(num1) - parseFloat(num2);
                    break;
                case '*':
                    re = parseFloat(num1) * parseFloat(num2);
                    break;
                case '/':
                    re = parseFloat(num1) / parseFloat(num2);
                    break;
                default:
                    alert('错误');
            }
            return re;
        }
        var num1 = prompt('输入第一个数字');
        var num2 = prompt('输入第二个数字');
        var operator = prompt('输入运算符+，-，*，/');
        var re;
        alert(getResult(num1, num2, operator));
    </script>
</head>

<body>

</body>

</html>